/**
教程地址：http://www.ng-newsletter.com/posts/chrome-apps-on-angular.html
**/


angular.module('weather')
.controller('MainController', function($scope, $timeout, WeatherService, UserService){
	$scope.date = {};
	//update time
	var updateTime = function(){
		$scope.date.raw = new Date();
		$timeout(updateTime,1000);
	}
	// launch update time
	updateTime();
	// API key 

	$scope.weather = {}

	$scope.user = UserService.user;
	// "Zhengzhou,Henan"
	WeatherService.getWeatherForecast($scope.user.location)
    .then(function(data) {
      	$scope.weather.forecast = data;
    });
})

.controller('SettingsController', function($scope, UserService, WeatherService) {
    $scope.user = UserService.user;
    console.log($scope.user)

    $scope.fetchCities = WeatherService.getCityDetails;

    $scope.save = function() {
      UserService.save();
    }
});